

#include "stdafx.h"
#include "CombatState_Peace.h"
#include "Combat/EvtCombat.h"
#include "Combat/CombatDefinition.h"
#include "Message/MsgCombat.h"
#include "Event/EvtImp.h"
#include "Combat/CombatSysImp.h"
#include "Entity/EntityIf.h"
#include "Scene/Scene.h"


CombatState_Peace::CombatState_Peace(void)

{
}

CombatState_Peace::~CombatState_Peace()
{
}

void
CombatState_Peace::enter()
{
	
}

void
CombatState_Peace::leave()
{
}


bool 
CombatState_Peace::update(int nElapse)
{
	return true;
}


void 
CombatState_Peace::onEvent(IEvt& evt)
{
	if (evt.getID()==EVT_CastStart)
	{
		LOG_ERROR_V("Failed to cast start in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastEnd)
	{
		LOG_ERROR_V("Failed to cast end in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastResult)
	{
		//
		//	No peace any more
		//	I am attacked
		//
		m_wpCombat->onEvent_CastResult(evt);
		m_wpCombat->setState(Combat::CBS_Ready);
	}
	else if (evt.getID()==EVT_TargetSelected)
	{
		//
		//	Peace is break, which player select a target
		m_wpCombat->onEvent_Target(evt);
		m_wpCombat->setState(Combat::CBS_Ready);
	}
	else if (evt.getID()==EVT_CastPrep)
	{
		m_wpCombat->onEvent_CastPrep(evt);
	}
}


CombatState_Peace_R::CombatState_Peace_R(void)

{
}

CombatState_Peace_R::~CombatState_Peace_R()
{
}

void
CombatState_Peace_R::enter()
{
	if (true) //m_wpEntity->isMe()
	{
		//
		//	Notify the combat module to start
		//
		m_wpEntity->getInputDevice()->post(new MsgCombatState(false));
	}
}

void
CombatState_Peace_R::leave()
{
	if (true)// m_wpEntity->isMe()
	{
		//
		//	Notify the combat module to start
		//
		m_wpEntity->getInputDevice()->post(new MsgCombatState(true));
	}
}


bool 
CombatState_Peace_R::update(int nElapse)
{
	return true;
}


void 
CombatState_Peace_R::onEvent(IEvt& evt)
{
	if (evt.getID()==EVT_CastStart)
	{
		LOG_ERROR_V("Failed to cast start in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastEnd)
	{
		LOG_ERROR_V("Failed to cast end in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastResult)
	{
		//
		//	No peace any more
		//	I am attacked
		//
		m_wpCombat->onEvent_CastResult(evt);
		m_wpCombat->setState(Combat::CBS_Ready);
	}
	else if (evt.getID()==EVT_TargetSelected)
	{
		//
		//	Peace is break, which player select a target
		m_wpCombat->onEvent_Target(evt);
		m_wpCombat->setState(Combat::CBS_Ready);
	}
	else if (evt.getID()==EVT_CastPrep)
	{
		m_wpCombat->onEvent_CastPrep(evt);
	}
}
